import { getAction } from '../../../api/manage'
import store from '@/store'

export default class CustomPalette {

  constructor(create, elementFactory, palette) {
    this.create = create;
    this.elementFactory = elementFactory;
    palette.registerProvider(this);
  }



  // 这个是绘制palette的核心，函数名不要变
  getPaletteEntries() {
    console.log('enter')
    const elementFactory = this.elementFactory;
    const create = this.create;
    let procdata=getAllProcessInfo();
    console.log('behind')
    function dragEventFactory(type,item) {
      return function (event) {
        const taskShape = elementFactory.create('shape', {
          type: type
        });
        taskShape.businessObject.name='我的原子服务Task_1'
        taskShape.businessObject.id='Task_1'
        // taskShape.businessObject.activiti.className='aaaaa'
        // taskShape.businessObject.activiticlass='aaaaaa'
        taskShape.businessObject.class=item.classDelegate
        create.start(event, taskShape);
        console.log( taskShape.businessObject.implementation)
      };
    }
     function getAllProcessInfo() {
      let processdata=store.state.atomic
       console.log('first')
       console.log(processdata)

       let temp = {}
       let index = 0;
       processdata.forEach(function(item) {
         index = index + 1
         console.log(item.classDelegate)
         console.log("here2");
         console.log(Object.keys(temp).length)
         let node = {
           // title: '我是自定义原子服务',    // 鼠标悬浮到节点上显示的文字
           title: 'wafvwaeweg',
           className: 'icon-custom myself-task',   // 样式名
           id: 'task_1',
           action: {      // 操作该节点时会触发的事件，此时只注册一个拖动事件即可，否则拖动时没有效果
             dragstart: dragEventFactory('bpmn:'+String(item.taskType),item),
             // click: elementRegistryFactory('bpmn:ServiceTask', { id:'Task_1' })
           }
         }
         let s = 'create.myself-task'
         s = s + String(index)
         temp[s] = node

       })
       console.log("here3");
       console.log(temp)
       return temp
     }
    return procdata


    // return {

    //   // 'create.myself-task': {
    //   //   title: '我是自定义原子服务',    // 鼠标悬浮到节点上显示的文字
    //   //
    //   //   className: 'icon-custom myself-task',   // 样式名
    //   //   id:'task_1',
    //   //   action: {      // 操作该节点时会触发的事件，此时只注册一个拖动事件即可，否则拖动时没有效果
    //   //     // dragstart: dragEventFactory('bpmn:ServiceTask'),
    //   //     dragstart: dragEventFactory('bpmn:ServiceTask'),
    //   //     // click: elementRegistryFactory('bpmn:ServiceTask', { id:'Task_1' })
    //   //   }
    //   // }
    // };
  }
}
CustomPalette.$inject = [
  'create',
  'elementFactory',
  'palette'
];